﻿using CleanArchitecture.Infrastructure.Entities;
using CleanArchitecture.Infrastructure.Interfaces.Business;
using CleanArchitecture.Infrastructure.Interfaces.Security;
using CleanArchitecture.Infrastructure.Models.Business.Columns;
using Microsoft.AspNetCore.Mvc;
using System.Linq;

namespace CleanArchitecture.Web.Components
{
    /// <summary>
    /// 前端功能组件 文章模块根据所属栏目分类查找上一篇及下一篇文章
    /// </summary>
    public class ArticlePrivatenNextViewComponent : ViewComponent
    {
        private readonly INewsService _newsService;

        public ArticlePrivatenNextViewComponent(INewsService newsService)
        {
            _newsService = newsService;
        }

        public IViewComponentResult Invoke(int curNewsId, ColumnItemModel curColumn = null)
        {
            var newsItems = _newsService.GetPrivateandNextNewsItems(curNewsId, curColumn == null ? 0 : curColumn.Id);
            string backUrl = curColumn == null ? "" : curColumn.UrlRoute;
            ViewBag.BackToUrl = backUrl;
            return View(newsItems);
        }
    }
}
